<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'header.php' ?>
<style type="text/css">
.dropdown-grade {
	margin-left: 10px;
}
.dropdown-grade li a{
	line-height: 24px;
}
#input-student {
	background-color: #FFF !important;
}
.div-submit {
	margin-top: 20px;
}
</style>
<div class="page-header">
	<h1>
		<a class="a-back" href="<?= admin_url('contents/result_data/' . $resultGradeId) ?>">
            <i class="fa fa-reply"></i>
		</a>
		<?php if(isset($resultId)): ?>
			修改学生成绩
		<?php else: ?>
			添加学生成绩
		<?php endif ?>

	</h1>
</div>
<div class="col-xs-12">
	<form id="result-form" class="form-horizontal">
		<input type="hidden" name="result_grade_id" value="<?= $resultGradeId ?>" />
		<input type="hidden" name="result_id" value="<?= isset($resultId) ? $resultId : '' ?>" />
		<input type="hidden" name="student_id" value="<?= isset($result['student_id']) ? $result['student_id'] : '' ?>" />
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right">学生名称：</label>
			<div class="col-sm-6">
				<span class="block input-icon input-icon-right pd0">
					<input class="form-control" id="select-student" type="text" name="student" value="<?= isset($result) ? $result['realname'] : '' ?>" 
					<?= isset($result) ? 'disabled' : '' ?> placeholder="请选择学生" />
					<i class="ace-icon fa fa-user"></i>
                </span>
			</div>
		</div>
		<?php foreach($resultGradeSubjectArr as $item): ?>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"><?= $item['lesson_name'] ?>分数：</label>
				<div class="col-sm-6">
					<input class="form-control" type="number" step="0.1" name="<?= $item['id'] ?>" value="<?= isset($result['scoreArr'][$item['id']]) ? $result['scoreArr'][$item['id']] : '0' ?>" />
				</div>
			</div>
		<?php endforeach ?>

		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right">评语：</label>
			<div class="col-sm-6">
				<textarea class="pd0" name="remark" style="height: 100px;width: 100%"><?= isset($result['remark']) ? $result['remark'] : '' ?></textarea>
			</div>
		</div>
        <div class="clearfix div-submit">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="submit">
                    <i class="ace-icon fa fa-check"></i> 提交
                </button>
            </div>
        </div>
	</form>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
console.log(<?= $gradeId ?>);
	var table = "";
	$(function(){
		// 初始化选择学生控件
		$("#select-student").selectStudent({
			"modalDataUrl": '<?= admin_url('contents/select_student_plugin_data_source') . '?grade_id=' . $gradeId ?>',
			"multiSelect": false,
			"resultDom": $("[name=student_id]")
		});

		// 提交表单
		var form = $("#result-form");
		var submitUrl = "<?=admin_url('contents/save_result_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('contents/result_data/' . $resultGradeId)?>";
				}
			});
		})
	})
</script>